package com.huawang.mdesign.model.service.constant;

import com.huawang.core.definition.mof.UMLDefinitionConstants;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

@Getter
public enum ValidationSeverityEnum {
    DEBUG(1, "调试", UMLDefinitionConstants.Customization_SeverityKind_Debug),
    INFO(2, "提示", UMLDefinitionConstants.Customization_SeverityKind_Info),
    WARN(3, "警告", UMLDefinitionConstants.Customization_SeverityKind_Warn),
    ERROR(4, "错误", UMLDefinitionConstants.Customization_SeverityKind_Error),
    FATAL(5, "致命", UMLDefinitionConstants.Customization_SeverityKind_Fatal);
    private final int code;
    private final String desc;
    private final String enumCode;


    ValidationSeverityEnum(int code, String desc, String enumCode) {
        this.code = code;
        this.desc = desc;
        this.enumCode = enumCode;
    }

    public static Set<String> getSeverityKinds(int code) {
        return Arrays.stream(values()).filter(validationSeverityEnum -> validationSeverityEnum.code >= code).
                map(ValidationSeverityEnum::getEnumCode).collect(Collectors.toSet());
    }

    public static Integer fromEnumCodeToCode(String enumCode) {
        if (Objects.equals(enumCode, UMLDefinitionConstants.Customization_SeverityKind_Debug)) {
            return DEBUG.code;
        } else if (Objects.equals(enumCode, UMLDefinitionConstants.Customization_SeverityKind_Info)) {
            return INFO.code;
        } else if (Objects.equals(enumCode, UMLDefinitionConstants.Customization_SeverityKind_Warn)) {
            return WARN.code;
        } else if (Objects.equals(enumCode, UMLDefinitionConstants.Customization_SeverityKind_Error)) {
            return ERROR.code;
        } else if (Objects.equals(enumCode, UMLDefinitionConstants.Customization_SeverityKind_Fatal)) {
            return FATAL.code;
        }
        return null;
    }
}
